﻿using KisayolYoneticisi.Source.BO;
using KisayolYoneticisi.Source.Util;
using System;
using System.Collections.Generic;
using System.IO;

namespace KisayolYoneticisi.Source.OpManager
{
    internal class ExportManager
    {
        internal static bool ExportToFile(List<Kisayol> list, string saveFile)
        {
            bool result = false;

            try
            {
                //KisayolAdi
                //Yol
                using (StreamWriter sWriter = new StreamWriter(new FileStream(saveFile, FileMode.OpenOrCreate)) { AutoFlush = true })
                {
                    // sWriter.AutoFlush = true;
                    sWriter.Write("{0}\t", "KisayolAdi");
                    sWriter.Write("{0}\t", "Yol");
                    sWriter.Write("\n");

                    foreach (Kisayol k in list)
                    {
                        sWriter.Write("{0}\t", ObjectUtility.ToStr(k.KisayolAdi).Replace("\n", " "));
                        sWriter.Write("{0}\t", ObjectUtility.ToStr(k.Yol).Replace("\n", " "));
                        sWriter.Write("\n");
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return result;
        }

    }
}